package transactionimplementation

import (
	"salary/database"
	"salary/model"
	"time"
)

type PaydayTransaction struct {
	payDate  	time.Time
	payCheck 	map[int]model.PayCheck
}

func (pt *PaydayTransaction) Execute() {
	ids := database.Database.GetAllEmployee()

	for _, id := range ids {
		e := database.Database.GetEmployee(id)
		if e != nil {
			if e.IsPayDate(pt.payDate) {
				pc := model.NewPaycheck(e.GetPayPeriodStartDate(pt.payDate), pt.payDate)
				pt.payCheck[id] = *pc
				e.Payday(*pc)
			}
		}
	}
}

func (pt *PaydayTransaction) GetPaycheck(empid int) model.PayCheck {
	if pc, ok := pt.payCheck[empid]; ok {
		return pc
	}
	return model.PayCheck{}
}

func (pt *PaydayTransaction) GetPaycheckCount() int {
	return len(pt.payCheck)
}
